﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Altairis.MailToolkit.ListManager.Pages {
    public partial class Login : System.Web.UI.Page {

        protected void Page_Load(object sender, EventArgs e) {
            if (this.RouteData.DataTokens["logout"] != null) {
                FormsAuthentication.SignOut();
                this.Response.RedirectToRoute("HomePage");
            }
        }

        protected void LoginControl_Authenticate(object sender, AuthenticateEventArgs e) {
            var lc = sender as System.Web.UI.WebControls.Login;
            if (bool.TrueString.Equals(ConfigurationManager.AppSettings["UseWebConfigUsersInsteadOfMembership"], StringComparison.OrdinalIgnoreCase)) {
                // Use user names and passwords from web.config file            
                e.Authenticated = FormsAuthentication.Authenticate(lc.UserName, lc.Password);
            }
            else { 
                // Use configured membership provider
                e.Authenticated = Membership.ValidateUser(lc.UserName, lc.Password);
            }
        }

    }
}